<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<!--#Include File="../include/md5.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_Master.asp
'= 摘    要：后台-管理员管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-10-10
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"31") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "add"
	Call Add_Admin
Case "save"
	Call Save_Admin
Case "del"
	Call deluser
Case Else
	Call Main
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Main
	Dim i,Temp,TopicList,ListBlock

	PageContent=Template.LoadTemplate("admin_master_list.htm")

	Template.SetVariable "Language_Comm_ListEmpty",str_Comm_ListEmpty,PageContent
	Template.SetVariable "Language_Comm_Bar_Operation",str_Comm_Bar_Operation,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Master_Help",str_Master_Help,PageContent

	Template.SetVariable "Language_Master_AccountList",str_Master_AccountList,PageContent
	Template.SetVariable "Language_Master_AddAccount",str_Master_AddAccount,PageContent

	Template.SetVariable "Language_Master_Account",str_Master_Account,PageContent
	Template.SetVariable "Language_Master_LastLoginTime",str_Master_LastLoginTime,PageContent
	Template.SetVariable "Language_Master_LastLoginIp",str_Master_LastLoginIp,PageContent
	Template.SetVariable "Language_Master_State",str_Master_State,PageContent
	Template.SetVariable "Language_Master_MasterTotal",str_Master_MasterTotal,PageContent

	ListBlock=Template.GetBlock("list",PageContent)

	TopicList=EA_M_DBO.Get_Master_List()
	If IsArray(TopicList) Then 
		For i=0 To UBound(TopicList,2)
			Temp=ListBlock

			Template.SetVariable "MasterID",TopicList(0,i),Temp
			Template.SetVariable "MasterAccount",TopicList(1,i),Temp
			Template.SetVariable "MasterLastLoginTime",TopicList(2,i),Temp
			Template.SetVariable "MasterLastLoginIp",TopicList(3,i),Temp
			Template.SetVariable "MasterState",TopicList(4,i),Temp

			Template.SetBlock "list",Temp,PageContent
		Next
    End If
	Template.CloseBlock "list",PageContent

	Template.SetVariable "MasterTotal",UBound(TopicList,2)+1,PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Add_Admin
	Dim PostId,BackName,State
	Dim Temp,ListBlock,ColumnList,Temp1,ListBlock1,RN
	Dim Userid,Power,Admin_Power
	Dim Level,i,j
	Dim ColumnName

	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	Temp=EA_M_DBO.Get_Master_Info(PostId)
	If IsArray(Temp) Then
		BackName=Temp(0,0)
		State=Temp(1,0)
	End If

	Temp=EA_M_DBO.Get_Master_Info(PostId)
	If IsArray(Temp) Then
		Power=Temp(2,0)
		Admin_Power=Temp(3,0)
		Admin_Power=","&Admin_Power&","
		Power=Power&","
	End If

	PageContent=Template.LoadTemplate("admin_master_option.htm")

	Template.SetVariable "Language_Comm_Save_Button",str_Comm_Save_Button,PageContent
	Template.SetVariable "Language_Comm_Reset_Button",str_Comm_Reset_Button,PageContent
	Template.SetVariable "Language_Comm_Enabled",str_Comm_Enabled,PageContent
	Template.SetVariable "Language_Comm_Disabled",str_Comm_Disabled,PageContent
	Template.SetVariable "Language_Comm_SelectAll",str_Comm_SelectAll,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Master_Help",str_Master_Help,PageContent

	Template.SetVariable "Language_Master_AccountList",str_Master_AccountList,PageContent
	Template.SetVariable "Language_Master_AddAccount",str_Master_AddAccount,PageContent

	Template.SetVariable "Language_Master_EditInfo",str_Master_EditInfo,PageContent
	Template.SetVariable "Language_Master_Account",str_Master_Account,PageContent
	Template.SetVariable "Language_Master_AddMaster_AccountInfo",str_Master_AddMaster_AccountInfo,PageContent
	Template.SetVariable "Language_Master_Password",str_Master_Password,PageContent
	Template.SetVariable "Language_Master_AddMaster_PasswordInfo",str_Master_AddMaster_PasswordInfo,PageContent
	Template.SetVariable "Language_Master_State",str_Master_State,PageContent
	Template.SetVariable "Language_Master_ColumnPowerOption",str_Master_ColumnPowerOption,PageContent
	Template.SetVariable "Language_Master_MenuPowerOption",str_Master_MenuPowerOption,PageContent

	Template.SetVariable "Language_Master_Column_Add",str_Master_Column_Add,PageContent
	Template.SetVariable "Language_Master_Column_Manager",str_Master_Column_Manager,PageContent
	Template.SetVariable "Language_Master_Column_Edit",str_Master_Column_Edit,PageContent
	Template.SetVariable "Language_Master_Column_Del",str_Master_Column_Del,PageContent

	Template.SetVariable "MasterID",PostId,PageContent
	Template.SetVariable "MasterAccount",BackName,PageContent
	Template.SetVariable "State_" & Abs(CInt(State))," checked",PageContent

	ListBlock=Template.GetBlock("list",PageContent)

	ColumnList=EA_DBO.Get_Column_List()
	If IsArray(ColumnList) Then
		For i=0 To UBound(ColumnList,2)
			Temp=ListBlock

			ColumnName = ""

			If Len(ColumnList(2,i))>4 Then ColumnName = "├"
			Level=(Len(ColumnList(2,i))/4-1)*4
			ColumnName = ColumnName & String(Level,"-")

			Template.SetVariable "ColumnID",ColumnList(0,i),Temp
			Template.SetVariable "ColumnName",ColumnName & ColumnList(1,i),Temp

			If InStr(Admin_Power,","&ColumnList(0,i)&"1,")>0 Then Template.SetVariable "Power_" & ColumnList(0,i) & "_1","checked",Temp
			If InStr(Admin_Power,","&ColumnList(0,i)&"2,")>0 Then Template.SetVariable "Power_" & ColumnList(0,i) & "_2","checked",Temp
			If InStr(Admin_Power,","&ColumnList(0,i)&"3,")>0 Then Template.SetVariable "Power_" & ColumnList(0,i) & "_3","checked",Temp
			If InStr(Admin_Power,","&ColumnList(0,i)&"4,")>0 Then Template.SetVariable "Power_" & ColumnList(0,i) & "_4","checked",Temp

			Template.SetBlock "list",Temp,PageContent
		Next
    End If
	Template.CloseBlock "list",PageContent


	ListBlock=Template.GetBlock("list1",PageContent)

	For i=0 To Ubound(str_LeftMenu)-1
		Temp=ListBlock

		ListBlock1=Template.GetBlock("list2",Temp)
		For j=1 To Ubound(str_LeftMenu,2)
			If IsEmpty(str_LeftMenu(i,j)) Then Exit For
			Temp1=ListBlock1
			
			RN = ""

			If j Mod 4 =0 Then RN = "<br>"

			Template.SetVariable "MenuName",str_LeftMenu(i,j) & RN,Temp1
			Template.SetVariable "Power",i&j,Temp1

			If InStr(Power,i&j&",")>0 Then Template.SetVariable "Power_" & i & j,"checked",Temp1
			
			Template.SetBlock "list2",Temp1,Temp
		Next
		Template.CloseBlock "list2",Temp

		Template.SetVariable "MenuName",str_LeftMenu(i,0),Temp

		Template.SetBlock "list1",Temp,PageContent
	Next
	Template.CloseBlock "list1",PageContent
	

	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Save_Admin
	Call EA_Pub.Chk_Post
	
	Dim UserId,Account,PassWord,PSQL,State
	Dim Admin_Power,Power

	UserId=EA_Pub.SafeRequest(3,"masterid",0,0,0)
	Account=EA_Pub.SafeRequest(2,"account",1,"",0)
	PassWord=EA_Pub.SafeRequest(2,"password",1,"",0)
	State=EA_Pub.SafeRequest(2,"state",0,0,0)

	Admin_Power=EA_Pub.SafeRequest(2,"admin_power",1,"",0)
	Power=EA_Pub.SafeRequest(2,"power",1,"",0)
	
	Admin_Power=Replace(Admin_Power," ","")
	Admin_Power=","&Admin_Power&","
	Power=Replace(Power," ","")
	
	If PassWord<>"" Then 
		PassWord=Md5(PassWord)
		PSQL=",master_password='"&PassWord&"'"
	End If
	If Account="" Or Len(Account)>50 Then 
		ErrMsg="登陆名为空或长度超过50个字符！"
		Call EA_Manager.Error(1)
	End If
	
	If UserId<>0 Then
		Sql="UpDate NB_Master Set Master_Name='"&Account&"',State="&State&""&PSQL&",Column_Setting = '"&Power&"', Setting = '"&Admin_Power&"' Where Master_Id="&UserId
		'response.write sql
		'response.end
		Conn.Execute(SQL)
	Else
		Sql="Select Master_Id From NB_Master Where Master_Name='"&Account&"'"
		Set rs=Conn.Execute(SQL)
		If Not rs.eof And Not rs.bof Then 
			FoundErr=True
			ErrMsg="对不起，后台登陆名重复！"
		ElseIf PassWord="" Then 
			FoundErr=True
			ErrMsg="对不起，请填写登陆密码！"
		Else
			SQL="INSERT INTO NB_Master ( Master_Name, Master_Password, State, Column_Setting, Setting )"
			SQL=SQL&" VALUES ('"&Account&"', '"&PassWord&"', "&State&", '"&Power&"', '"&Admin_Power&"')"
			Conn.Execute(SQL)
		End If
		If FoundErr Then Call EA_Manager.Error(1)
	End If
	
	Set Rs=Nothing
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect "admin_master.asp"
End Sub

Sub deluser()
	Call EA_Pub.Chk_Post
	
	Dim UserId
	UserId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	SQL="DELETE"
	SQL=SQL&" FROM NB_Master"
	SQL=SQL&" WHERE Master_Id="&UserId&" And Master_Name<>'"&Session(sCacheName&"master_name")&"'"
	Conn.Execute(SQL)
	
	Set Rs=Nothing
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub
%>
